package com.hsq.androidproject.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.lenovo.androidproject3.R;
import com.hsq.androidproject.entity.rtv;
import com.hsq.androidproject.ui.rtvActivity;

import java.util.List;

/**
 * Created by Administrator on 2017/3/17.
 */

public class MyGridViewStartAdapter extends BaseAdapter {
    Context con;
    List<rtv> mdata;

    public MyGridViewStartAdapter(Context con, List<rtv> mdata) {
        this.con = con;
        this.mdata = mdata;
    }

    @Override
    public int getCount() {
        return mdata.size();
    }

    @Override
    public Object getItem(int position) {
        return mdata.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        final rtv  rtvbean=mdata.get(position);
        String isFinished=rtvbean.getIsFinished();
        final int i=rtvbean.getCount();
        final int r=rtvbean.getRank();
        view=LayoutInflater.from(con).inflate(R.layout.gridviewitem,parent,false);
        final    ImageView imageView;
            final  String  thumb=rtvbean.getBitmap();
        imageView= (ImageView) view.findViewById(R.id.gridiv_img);
        TextView count,name,rank;
        count= (TextView) view.findViewById(R.id.gridcount);
        name= (TextView) view.findViewById(R.id.gridname);
        rank= (TextView) view.findViewById(R.id.gridrank);
            Glide.with(con)
                .load(thumb)

                .into(imageView);
        if(isFinished.equals("false")){
            count.setText("更新至第"+i+"集");
        }else{
            count.setText(i+"集全");
        }

        name.setText(rtvbean.getName()+"");
        int rs=r/10;
        rank.setText(rs+"");
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(con, rtvActivity.class);
                intent.putExtra("rtvbean",rtvbean);
                con.startActivity(intent);
            }
        });

        return view;
    }
}
